/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: op execute.
 * Author: qingjicheng
 * Create: 2022-11-28
 */

#ifndef OP_EXECUTOR_H
#define OP_EXECUTOR_H

#include "hccl_operator.h"
#include "transport_heterog_pub.h"
#include "mem_host_pub.h"
#include "es_utils.h"
namespace hccl {
namespace {
    constexpr u32 LOOP_SLEEP_TIME_US = 10;
    constexpr u32 LOOP_IMPROBE_SLEEP_TIME_US = 10;
    constexpr u32 KEY_SIZE = sizeof(u64);
}

enum EmbeddingServiceRecvOutputIndex {
    OUTPUT_REQ_STATUS_IDX = 0,
    OUTPUT_KEY_OFFSET_IDX = 1,
    OUTPUT_ACTUAL_KEY_COUNT_IDX = 2,
    OUTPUT_WORKER_RANKID_IDX = 3,
    OUTPUT_REPONSE_BUFFER_IDX = 4,
    OUTPUT_IDX_NUM = 5
};

class OpExecutor {
public:
    explicit OpExecutor() = default;
    virtual ~OpExecutor() = default;
    virtual HcclResult ExecuteOp(HcclOpPtr opPtr) = 0;
protected:
    HcclResult Send(TransTask *taskPtr, TransportHeterog *transportPtr) const;
    HcclResult Isend(TransTask *taskPtr, TransportHeterog *transportPtr, HcclRequestInfo *&request) const;
    void GetProbeMsgInfo(TransportHeterog *heterogPtr, HcclMessageInfo *msg, u32 &recvDataType,
        HcclUserRequire &userRequire);
    void SetTaskOutputRegStatusInfo(TransTask *taskPtr,  HcclStatus &status, u32 &recvDataType,
        HcclUserRequire &userRequire);
    template<typename ParamType> std::queue<OpTaskPtr> &GetTaskQue(HcclOpPtr opPtr)
    {
        HcclOperator<ParamType> *ptr = static_cast<HcclOperator<ParamType> *>(opPtr);
        return ptr->taskQue_;
    }
};
}
#endif